﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace NetMonitor.Server
{
    public class NetMonClient
    {        
        private NetMonServer srv;
        
        private NetMonClient(string ipAddress)
        {
            if ((ipAddress == null) || (ipAddress.Length == 0))
                ipAddress = "localhost";
            ChannelServices.RegisterChannel(new TcpClientChannel(), false);
            srv = (NetMonServer)Activator.GetObject(typeof(NetMonServer), "tcp://" + ipAddress +":6666/NetMonSrv");
        }

        public string checkConnectivity(string name)
        {            
            return srv.checkConnectivityStatus(name);
        }

        public string readConfig()
        {
            return srv.readConfig();
        }

        public void writeConfig(string value)
        {
            srv.writeConfig(value);
        }

        private static NetMonClient client;
        public static NetMonClient GetClient(string ipAddress)
        {
            if (client == null)
                client = new NetMonClient(ipAddress);
            return client;
        }
    }
}
